<?php

G::LoadClass ( 'pmFunctions' );
$G_PUBLISH = new Publisher ();

$sReportUid = $_GET['u'];

require_once ( "classes/model/RptReports.php" );
$tr = RptReportsPeer::retrieveByPK( $sReportUid  );

if ( ( is_object ( $tr ) &&  get_class ($tr) == 'RptReports' ) ) {
  $fields00['REPORTCODE'] = $tr->getReportcode();
  $fields00['REPORTDESCRIPTION'] = $tr->getReportdescription();
  $fields00['REPORTTITLE'] = $tr->getReporttitle();
  $fields00['REPORTSUBTITLE'] = $tr->getReportsubtitle();
  $fields00['REPORTFIELDTITLES'] = explode( "|", $tr->getReportfieldtitles() );
  $fields00['REPORTFIELDGROUPS'] = explode( "|", $tr->getReportfieldgroups() );
  $fields00['REPORTSQL'] = $tr->getReportsql();
} else
  $fields00 = array();

//G::pr("Report CODE [" . $sReportUid . "]");
//G::pr($fields00);

if ( sizeof($fields00) > 0 ) {
  $G_MAIN_MENU = 'processmaker';
  $G_SUB_MENU = 'hr/menuhrParameters';
  $G_ID_MENU_SELECTED = 'ID_HR_PAR';
  $G_ID_SUB_MENU_SELECTED = 'ID_HR_GENDERS';

  $G_PUBLISH = new Publisher;

  $aResult = executeQuery($fields00['REPORTSQL']);

  $aFields['PAGE_TITLE'] = $fields00['REPORTTITLE'];
  $aFields['PAGE_SUBTITLE'] = $fields00['REPORTSUBTITLE'];
  $aFields['ROWS_TITLES'] = $fields00['REPORTFIELDTITLES'];
  $aFields['GROUPS'] = $fields00['REPORTFIELDGROUPS'];
  $aFields['GROUPS_MAX'] = sizeof($aFields['GROUPS']);
  $aFields['ROWS_DATA'] = $aResult;
  $aFields['ROWS_MAX'] = sizeof($aResult);

  $G_PUBLISH->AddContent('smarty', 'hr/rpt', '', '', $aFields);
  G::RenderPage('publish', 'blank');

} else {
  $G_PUBLISH = new Publisher;
  $aMessage['MESSAGE'] = "ERROR: report not found.";
  $G_PUBLISH->AddContent('xmlform', 'xmlform', 'login/showMessage', '', $aMessage );
  G::RenderPage( 'publish', 'blank' );

}

